import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int size = in.nextInt();
        int[] array = new int [size];
        for(int i = 0 ;i < size ; i++){
            array[i] = in.nextInt();
        }
        int sum = array[0];
        int max = array[0];
        for(int i = 1 ; i < size; i++){
            sum = Max(sum + array[i],array[i]);
            if(sum > max){
                max = sum;
            }
        }
        System.out.print(max);
    }

    public static int Max(int a,int b){
        return a > b ? a : b;
    }
}